<template>
  <div class="page">
    <div class="nav-bar flex-row">
      <div class="logo">
        Mtime
      </div>
      <div class="nav-item">首页</div>
      <div class="nav-item actived">
        电影
      </div>
      <div class="nav-item">原创</div>
      <div class="nav-item">榜单</div>
      <div class="nav-item">社区</div>
      <div class="nav-item">视频</div>
    </div>
    <div class="color-background"></div>
    <div class="search-box">
      <div class="search-content flex-row">
        <div class="all-button">全部</div>
        <div class="iconfont icon-xia"></div>
        <div class="split-v"></div>
        <input class="keyword" v-model="keyword" type="text" placeholder="搜索电影、影人、文章、用户、家族" />
        <div class="iconfont icon-search" @click="loadMovieList()"></div>
      </div>
    </div>
    <div class="page-content flex-column">

      <div class="content-menu flex-row">
        <div class="menu-item actived">影视</div>
        <div class="menu-item">影人</div>
        <div class="menu-item">内容</div>
        <div class="menu-item">用户</div>
        <div class="menu-item">家族</div>
      </div>
      <div class="selected-box page-box flex-row">
        <div class="box-label">
          已选择：
        </div>
        <div class="selected-items flex-row">
          <div class="selected-item" v-if="currentType!=null">
            {{ currentType.name }}
            <div class="iconfont icon-delete" @click="removeCurrentType()"></div>
          </div>
          <div class="selected-item" v-if="currentYear!=null">
            {{currentYear}}年
            <div class="iconfont icon-delete" @click="removeCurrentYear()"></div>
          </div>
        </div>
      </div>
      <div class="split-line"></div>
      <div class="types-box page-box flex-row">
        <div class="box-label">
          类型：
        </div>
        <div class="type-items flex-row">
          <div class="type-item"
               :class="{'actived':currentType!=null&&currentType.typeId==typeItem.typeId}"
               v-for="typeItem in typeList"
               :key="typeItem.typeId"
               @click="typeClick(typeItem)"
          >
            {{typeItem.name}}
          </div>

        </div>
      </div>
      <div class="split-line"></div>
      <div class="years-box page-box flex-row">
        <div class="box-label">
          年代：
        </div>
        <select class="year-select" v-model="currentYear" @change="yearChange">
          <option class="year-item"
                  v-for="yearItem in yearList"
                  :key="yearItem.movieYear"
                  :value="yearItem.movieYear"
          >{{ yearItem.movieYear }}</option>
        </select>
      </div>
      <div class="split-line"></div>
      <div class="page-box total-text flex-row">
        <div class="box-label">相关影视：</div>
        <div class="number">{{total}}</div>个
      </div>
      <div class="movie-box page-box flex-column">
        <div class="movie-item" v-for="movieItem in movieList" :key="movieItem.movieId">
          <div class="movie-ratio-box">
            <div class="ratio-label">总评分</div>
            <div class="ratio-value">{{ parseFloat(movieItem.rating).toFixed(1) }}</div>
          </div>
          <div class="movie-info-box">
            <div class="movie-title">{{ movieItem.name }} {{ movieItem.nameEn }} （{{ movieItem.movieYear }}）</div>
            <div class="movie-info">
              <div class="movie-image">
                <img :src="movieItem.img" />
              </div>
              <div class="movie-detail">
                <div class="line-text">{{movieItem.length}}分钟 - 类型： {{ movieItem.typeName.split(",").join(" / ") }}</div>
                <div class="line-text">导演： {{ movieItem.directorName }}</div>
                <div class="line-text">主演： {{ movieItem.actorsName.split(",")[0] }}</div>
                <div class="movie-button">查看详情</div>
              </div>
            </div>
          </div>
        </div>



      </div>
      <div class="page-box flex-row" id="pagingBox">
        <div class="last-button actived">&lt;</div>
        <div class="number-button actived">1</div>
        <div class="number-button">2</div>
        <div class="number-button">3</div>
        <div class="number-button">4</div>
        <div class="number-button">5</div>
        <div class="number-button">6</div>
        <div class="number-button">...</div>
        <div class="number-button">12</div>
        <div class="next-button">&gt;</div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "index",
  data(){
    return{
      typeList:[], //分类数组
      currentType:null, //当前选择的影片分类
      yearList:[], //年份数组
      currentYear:null, //当前选择的年份
      keyword:"", //搜索关键字
      movieList:[],
      total:0 //影片总数
    }
  },
  methods:{
    //加载影片分类数据
    loadTypeList(){
      //使用axios进行http请求
      this.$http.get("/api/movies/categories")
          .then((response)=>{
        console.log("获取到影片分类数据：",response);
        if(response.status==200){
          //将http请求到的分类数据，赋值给界面变量typeList
          this.typeList=response.data;
        }
      })
    },
    //加载年份列表
    loadYearList(){
       this.$http.get("/api/movies/years").then((response)=>{
         if(response.status==200){
           this.yearList=response.data;
         }
       })
    },
    //分类点击
    typeClick(typeItem){
      this.currentType=typeItem;
      this.loadMovieList();
    },
    //移除已选择分类
    removeCurrentType(){
      this.currentType=null;
      this.loadMovieList();
    },
    removeCurrentYear(){
      this.currentYear=null;
      this.loadMovieList();
    },
    yearChange(e){
      console.log("年份切换:",e);
      this.loadMovieList();
    },
    //查询影片列表
    loadMovieList(){
      let url="api/movies/movie-list?a=1";
      if(this.keyword!=""){
        url+="&keyword="+this.keyword;
      }
      if(this.currentType!=null){
        url+="&categories="+this.currentType.typeId;
      }
      if(this.currentYear!=null){
        url+="&movie_year="+this.currentYear;
      }
      this.$http.get(url).then((response)=>{
        console.log("获取到影片数据:",response);
        if(response.status==200){
          if(response.data && response.data.content){
            this.movieList=response.data.content
          }
          if(response.data && response.data.totalElements){
            this.total=response.data.totalElements;
          }

        }
      })
    }
  },
  mounted() {
    //调用获取影片分类
    this.loadTypeList();
    //调用获取年份列表
    this.loadYearList();
    //调用影片列表
    this.loadMovieList();
  }
}
</script>

<style scoped>
@import url("//at.alicdn.com/t/font_2863451_npexvzpdos.css");

.flex-row {
  display: flex;
  flex-direction: row;
  align-items: center;
}

.flex-column {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.page {
  width: 100%;
  padding-top: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.nav-bar {
  width: 100%;
  background-color: #1e2736;
  height: 60px;
  color: rgba(200, 200, 200, 1);
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10;
}

.nav-bar .logo {
  font-size: 200%;
  font-weight: bold;
  margin-left: 10%;
  margin-right: 60px;
  color: #fff;
}

.nav-item {
  width: 80px;
  position: relative;
  font-size: 16px;
  cursor: pointer;
}

.nav-item.actived {
  color: #fff;
  font-weight: 500;
}

.nav-item.actived:after {
  content: '';
  width: 0;
  height: 0;
  border: 6px solid transparent;
  border-bottom-color: #fff;
  position: absolute;
  bottom: -20px;
  left: 8px;
}

.color-background {
  position: absolute;
  top: 60px;
  left: 0;
  width: 100%;
  background-color: #127bab;
  height: 300px;
}

.page-content {
  width: 80%;
  background-color: #fff;
  overflow-y: auto;
  z-index: 5;
  margin-top: 100px;
  position: relative;
  padding-top: 60px;
}

.search-box {
  width: 50%;
  height: 60px;
  margin: 0 auto;
  background-color: #127bab;
  padding: 10px;
  position: absolute;
  top: 120px;
  left: 25%;
  border-radius: 40px;
  z-index: 8;
  display: flex;
  justify-content: center;
  align-items: center;
}

.search-box .search-content {
  width: calc(100% - 10px);
  height: 50px;
  border-radius: 25px;
;
  background-color: #fff;
}

.search-box .search-content .all-button {
  margin-left: 20px;
  width: 60px;
  text-align: center;
  color: #33334d;
}

.search-box .search-content .icon-xia {
  margin-right: 20px;
}

.search-box .search-content .split-v {
  height: 30%;
  border-left: 1px solid rgba(200, 200, 200, 1);
  margin-right: 20px;
}

.search-box .search-content .keyword {
  height: calc(100% - 2px);
  border: none;
  flex: 1;
}

.keyword:focus {
  outline: none;
}

.search-box .search-content .icon-search {
  width: 40px;
  font-size: 150%;
  cursor: pointer;
}

.content-menu {
  width: calc(100% - 100px);
  padding: 0 50px;
  border-bottom: 1px solid rgba(200, 200, 200, 0.9);
  margin-bottom: 20px;
}

.content-menu .menu-item {
  padding: 10px 20px;
  margin-left: 10px;
  margin-right: 10px;

}

.content-menu .menu-item.actived {
  border-bottom: 2px solid #DF4706;
}

.page-box {
  margin-left: 50px;
  margin-right: 50px;
  padding: 20px 0;
  border-bottom: 1px dotted rgba(200, 200, 200, 0.5);
  align-items: flex-start;
}

.page-box .box-label {
  width: 100px;
  flex-shrink: 0;
  color: #333;
}

.selected-items {}

.selected-item {
  border: 1px solid #0087e2;
  color: #0087e2;
  padding: 5px 10px;
  background-color: #ecf5ff;
  margin-right: 15px;
  border-radius: 4px;
  position: relative;
  padding-right: 30px;
  cursor:pointer;
}

.selected-item .icon-delete {
  width: 20px;
  height: 20px;
  line-height: 20px;
  position: absolute;
  top: calc((100% - 20px) / 2);
  right: 5px;
  color: #0087e2;
  cursor: pointer;
}

.type-items {
  flex-wrap: wrap;
  align-items: flex-start;
}

.type-items .type-item {
  margin-right: 10px;
  margin: 0px 25px 25px 0px;
  color: #4e5e73;
  cursor:pointer;
}

.type-items .type-item.actived {
  color: #20a0da;
}

.years-box {
  align-items: center;
}

.year-select {
  width: 200px;
  padding: 0 10px;
  height: 40px;
  border-radius: 4px;
  border: 1px solid rgba(200, 200, 200, 0.5);
  cursor: pointer;
}

.year-select:focus {
  outline: none;
}

.movie-item {
  padding-left: 90px;
  position: relative;
  zoom: 1;
  margin-bottom: 40px;
}

.movie-item .movie-ratio-box {
  position: absolute;
  left: 20px;
  top: 33px;
  width: 55px;
  height: 55px;
  text-align: center;
  background: #679c21;
  color: #fff;

}

.movie-item .movie-ratio-box .ratio-label {
  padding: 4px 0 0;
  font-weight: 400;
  font-size: 12px;
  display: inline-block;
}

.movie-item .movie-ratio-box .ratio-value {
  font-size: 23px;
  font-weight: 700;
  position: absolute;
  left: 10px;
  top: 23px;
  text-align: center;

}

.movie-image {
  overflow: hidden;
  display: block;
  float: left;
  margin-top: -15px;
}

.movie-image img {
  width: 98px;
  height: 130px;
  vertical-align: top;
  border: 1px solid #c4c4c4;
  cursor: pointer;
}

.movie-detail{
  float: left;
  width: 450px;
  margin-top: -22px;
  margin-left: 10px;
  font-size: 13px;
  line-height: 10px;

}
.line-text{
  margin: 18px 0;

}

.movie-title{
  font-size: 20px;
  line-height: 24px;
  font-weight: 400;
  padding: 30px 0;
  background: #fff;
}
.movie-button{

  background: #679c21;
  border-radius: 18px;
  color: #fff;
  width: 124px;
  height: 28px;
  font-size: 14px;
  line-height: 28px;
  overflow: hidden;
  text-align: center;
  float: left;
  letter-spacing: 2px;
  margin-top: 5px;
  margin-left: 5px;
}



#pagingBox{
  text-align: center;
  white-space: nowrap;
  padding: 2px 5px;
  color: #303133;
  font-weight: 700;
  display: flex;
  justify-content: center;
  margin-bottom: 25px;

}

.last-button{
  padding: 0 4px;
  font-size: 20px;
  min-width: 35.5px;
  height: 28px;
  line-height: 28px;
  box-sizing: border-box;
  text-align: center;
  background-color: #f4f4f5;
  cursor: pointer;
}
.last-button.actived{
  cursor: not-allowed;
  color: #c0c4cc;
}

.number-button{
  padding: 0 4px;
  font-size: 13px;
  min-width: 35.5px;
  height: 28px;
  line-height: 28px;
  box-sizing: border-box;
  text-align: center;
  background-color: #f4f4f5;
  margin-left: 15px;
  border-radius: 4px;
  cursor: pointer;
}
.number-button.actived{
  background-color: #409eff;
  color: #fff;

}
.next-button{
  padding: 0 4px;
  font-size: 20px;
  min-width: 35.5px;
  height: 28px;
  line-height: 28px;
  box-sizing: border-box;
  text-align: center;
  background-color: #f4f4f5;
  margin-left: 15px;
}

</style>